package com.ytclub.wx.handler;

import com.ytclub.wx.constants.WxConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 微信关注消息处理类
 *
 * @author: HuangQi
 * @date: Created in 20:41 2024/3/25
 * @description: 微信关注消息处理
 */
@Component
@Slf4j
public class SubscribeMsgHandler implements WxChatMsgHandler {

    /**
     * 关注回复内容
     */
    private static final String SUBSCRIBE_CONTENT = "感谢您的关注，我是零の守墓人！欢迎关注猿测试项目";


    /**
     * 获取用户关注消息类型
     *
     * @return 用户关注消息类型
     */
    @Override
    public WxChatMsgTypeEnum getMsgType() {
        return WxChatMsgTypeEnum.SUBSCRIBE;
    }

    /**
     * 处理用户关注消息
     *
     * @return 处理结果
     */
    @Override
    public String dealMsg(Map<String, String> msgMap) {
        log.info(WxConstant.SUBSCRIBE_LOG_INFO);
        String fromUserName = msgMap.get(WxConstant.FROMUSERNAME);
        String toUserName = msgMap.get(WxConstant.TOUSERNAME);
        String content = "<xml>\n" +
                "  <ToUserName><![CDATA[" + fromUserName + "]]></ToUserName>\n" +
                "  <FromUserName><![CDATA[" + toUserName + "]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA[" + SUBSCRIBE_CONTENT + "]]></Content>\n" +
                "</xml>";
        return content;
    }
}
